package com.web.controller;


import com.web.annotation.CurrentUser;
import com.web.annotation.LoginRequired;
import com.web.domain.Response;
import com.web.entity.ReportUserInfo;
import com.web.entity.UserInfo;
import com.web.service.ReportService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 举报表
 */
@Slf4j
@RestController
@RequestMapping("/app")
public class ReportController {
    @Resource
    private ReportService reportService;


    /**
     * 获取举报类型基础表
     * @return
     */
    @RequestMapping("/get/report/info")
    @LoginRequired
    public Response getReportInfo(){
        return Response.custom().ok().addParams(reportService.getAllReportInfo());
    }

    /**
     * 统一举报接口
     * @param info
     * @param type
     * @param typeId
     * @param reportId
     * @param content
     * @return
     */
    @RequestMapping("/add/report")
    public Response addReport(@CurrentUser UserInfo info,String type,String typeId,Integer reportId,String content){
        if (StringUtils.isBlank(type) || StringUtils.isBlank(typeId) || reportId == null || StringUtils.isBlank(content)){
            return Response.custom().failure("缺少必要参数!");
        }
        reportService.addReportUserInfo(new ReportUserInfo(reportId,info.getUserId(),typeId,type,content,new Date(),new Date()));
        return Response.custom().ok();
    }
}
